package com.colud.colud_example_service.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.colud.colud_example_service.model.Goods;
import com.colud.colud_example_service.service.GoodsService;

@RestController
public class ShoppingController {
	@Autowired
	private GoodsService goodsService;
    @RequestMapping(value = "/shopping" ,method = RequestMethod.GET)
    public String shopping(@RequestParam(value="434") String code, @RequestParam(value="3534") Integer num,HttpServletRequest request) {
    	String user=(String)request.getSession().getAttribute("user");
    	if(user!=null&&!user.trim().equals("")){
    		System.out.println(user);
    	}else{
    		request.getSession().setAttribute("user", "wwww");
    	}
        System.out.println(num+"件"+code+"(商品编码)添加进购物车");
        return num+"件"+code+"(商品编码)添加进购物车";
    }
    
    //根据返回所有商品
    @RequestMapping(value = "/getAllGoods" ,method = RequestMethod.GET)
    @ResponseBody
    public List<Goods> getAllGoods() {
    	List<Goods> listGoods = goodsService.getAllGoods();
    	
        if(!listGoods.isEmpty()){
            System.out.println("listCart.get(0).getGoodsCount():"+listGoods.get(0).getGoodName());
        }
        return listGoods;
    }
}
